import tkinter

import pyautogui
import time
import pyperclip
import pyscreeze


class Flag:
    def __init__(self, box, f_type):
        self.Box = box
        self.Type = f_type


flags_ppt = []
flags_view = []
flags_book = []


def find_img():
    global flags_ppt, flags_view, flags_book
    try:
        img_ppt_list = list(pyautogui.locateAllOnScreen("img\\ppt.png", confidence=0.95))
        if len(img_ppt_list) != 0:
            flags_ppt = []
            for i_ppt in img_ppt_list:
                flags_ppt.append(Flag(i_ppt, 'ppt'))
    except Exception as e:
        print(e)
    try:
        img_book_list = list(pyautogui.locateAllOnScreen("img\\book.png", confidence=0.95))
        if len(img_book_list) != 0:
            flags_book = []
            for i_book in img_book_list:
                flags_book.append(Flag(i_book, 'book'))
    except Exception as e:
        print(e)
    try:
        img_view_list = list(pyautogui.locateAllOnScreen("img\\view.png", confidence=0.9))
        if len(img_view_list) != 0:
            flags_view = []
            for i_view in img_view_list:
                flags_view.append(Flag(i_view, 'view'))
    except Exception as e:
        print(e)


def run():
    global b1
    b1.config(state="disabled")
    b1.config(text='程序已经开始！', fg='blue', bg='white')
    find_img()
    for i in flags_ppt:
        pyautogui.click(i.Box)
        time.sleep(0.7)
    for i in flags_book:
        pyautogui.click(i.Box)
        time.sleep(0.7)
    for i in flags_view:
        pyautogui.click(i.Box)
        time.sleep(15 * 60)


root = tkinter.Tk()
root.title('数据结构刷课小程序V1.0——@赛博疯子')
root.geometry('600x400')
root.resizable(False, False)
tkinter.Label(root, text='记得看附带的操作说明！', width=56, height=5).grid(column=0, row=0)
b1 = tkinter.Button(root, text='开始！（开始后不要碰电脑）', fg='#525D71', bg='#A7CBDC', command=run)
b1.grid(column=0, row=1)
b1.place(x=150, y=150)
root.mainloop()
